﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BoneImp {
	partial class Skeleton {
		public static Skeleton LoadFromSpine(string JsonFile, string AtlasFile) {
			Atlas atlas = Atlas.readAtlasFile(AtlasFile);
			SkeletonJson json = new SkeletonJson(atlas);
			SkeletonData skeletonData = json.readSkeletonDataFile(JsonFile);

			AnimationStateData stateData = new AnimationStateData(skeletonData);
			stateData.setMixByName("walk", "jump", 0.4f);
			stateData.setMixByName("jump", "walk", 0.4f);

			return new Skeleton(skeletonData, stateData);
		}

		private static string StripFilename(string filepath) {
			int last = filepath.LastIndexOfAny(new char[] { '\\', '/' });
			if(last == -1) {
				return "";
			}

			return filepath.Substring(0, last + 1);
		}

		public static Skeleton LoadFromSpine(string JsonFile) {
			SkeletonJson json = new SkeletonJson(StripFilename(JsonFile));
			SkeletonData skeletonData = json.readSkeletonDataFile(JsonFile);

			AnimationStateData stateData = new AnimationStateData(skeletonData);
			stateData.setMixByName("walk", "jump", 0.4f);
			stateData.setMixByName("jump", "walk", 0.4f);

			return new Skeleton(skeletonData, stateData);
		}
	}
}
